
package testcases;

import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;

import framework.HelperFunctions;
import framework.Resultdata;

public class LoginProcess {

  public static String $username, $password, testCase, assertcheck;
  public static String moduleName = "Login and Authorisation";
  public static boolean status;

  public static void validLogin(LoggingDefaultSelenium selenium)
  {
    
	testCase = "Login";
    assertcheck = "Valid Login Test";
    
    // selenium.setSpeed("1000");
    HelperFunctions.focusAndType(selenium, GuiMap.login_txtusername, "ap_hilary");
    HelperFunctions.focusAndType(selenium, GuiMap.login_txtpassword, "Ebuying20");
//    HelperFunctions.focusAndClickAndWait(selenium, GuiMap.login_btnsubmit);
    HelperFunctions.clickAndWait(selenium, GuiMap.login_btnsubmit, GuiMap.menuBids);
       status = selenium.isTextPresent("Welcome Hilary");
    // LoggerMethod.logToResultMap(status, moduleName, testCase, assertcheck);
    Resultdata.insertResultToMap(moduleName, testCase, assertcheck, "Failed");
    Resultdata.insertResultToMap(moduleName, testCase, assertcheck, "Passed");
    // bids Insertion just for test
    

    HelperFunctions.clickAndWait(selenium, GuiMap.menuBids, GuiMap.menuBidsEnqBids);
    HelperFunctions.clickAndWait(selenium, GuiMap.menuBidsEnqBids, GuiMap.bidHammer);
    HelperFunctions.clickAndWait(selenium, GuiMap.bidHammer,  GuiMap.bidmanualbid);
    selenium.setTimeout("20000");
    HelperFunctions.focusAndType(selenium, GuiMap.bidmanualbid, "9");
    selenium.setTimeout("3000");
    HelperFunctions.focusAndType(selenium, GuiMap.bidleadtime, "5");
    selenium.setTimeout("3000");
    HelperFunctions.focusAndType(selenium, GuiMap.bidqty, "10");
    selenium.setTimeout("3000");
    HelperFunctions.clickAndWait(selenium, GuiMap.bidplacehammer,  GuiMap.datasave);
//    HelperFunctions.focusAndClickAndWait(selenium, GuiMap.bidplacehammer);
           
  }

  public static void invalidLogin(LoggingDefaultSelenium selenium) {
    testCase = "Invalid Login Test";
    selenium.type(GuiMap.login_txtusername, "ss");
    selenium.type(GuiMap.login_txtpassword, "ss");
    selenium.setTimeout("30000");
    selenium.click(GuiMap.login_btnsubmit);
    selenium.waitForPageToLoad("30000");
    status = selenium.isTextPresent("Username and/or the password is not right");
    // LoggerMethod.logToResultMap(status, testName, testMethod);
  }

  public static void emptyUsernamePassword(LoggingDefaultSelenium selenium) {
	  
    testCase = "Empty Username or Password";
    selenium.type(GuiMap.login_txtusername, $username);
    selenium.type(GuiMap.login_txtpassword, $password);
    selenium.click(GuiMap.login_btnsubmit);
    if ($username == "") {
      status = selenium.isTextPresent("Username should not be empty");
      // LoggerMethod.logToResultMap(status, testName, testMethod);
    } else if ($password == "") {
      status = selenium.isTextPresent("Password should not be empty");
      // LoggerMethod.logToResultMap(status, testName, testMethod);
    }

    else if (($username == "") & ($password == "")) {
      status = selenium.isTextPresent("Username and Password should not be empty");
      // LoggerMethod.logToResultMap(status, testName, testMethod);
    }
  }

}
